/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.swinvehicle.drivers;

import au.edu.swin.swinvehicle.driver.DriverDetailsTO;
import au.edu.swin.swinvehicle.driver.DriverException;
import au.edu.swin.swinvehicle.driver.DriverRemote;
import au.edu.swin.swinvehicle.driverlicencetype.DriverLicenceTypeEntity;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;

/**
 *
 * @author Alexandra
 */
public class DriverJSFManagedBean {

    @EJB
    private DriverRemote driverRemote;
    public List<DriverDetailsTO> allDrivers;
    public DriverDetailsTO driverDetailsTO;
    private Long id;
    private String userName;
    private String firstName;
    private String lastName;
    private String emailAddress;
    private String contactNumber;
    private String homeAddress;
    private String driverLicenceCode;
    private String driverLicenceDescription;

    public DriverDetailsTO getDriverDetailsTO() {
        return driverDetailsTO;
    }

    public void setDriverDetailsTO(DriverDetailsTO driverDetailsTO) {
        this.driverDetailsTO = driverDetailsTO;
    }

    public List<DriverDetailsTO> getAllDrivers() {
        if (allDrivers == null || allDrivers.size() < 1) {
            try {
                setAllDrivers(driverRemote.getAllDrivers());
            } catch (DriverException ex) {
                Logger.getLogger(DriverJSFManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        return allDrivers;
    }

    public void setAllDrivers(List<DriverDetailsTO> allDrivers) {
        this.allDrivers = allDrivers;
    }

    public void viewDriverDetails() {
        try {
            //load userDetails
            setAllDrivers(driverRemote.getAllDrivers());
        } catch (DriverException ex) {
            Logger.getLogger(DriverJSFManagedBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    

    public void addDriver() {
        DriverDetailsTO dDetailsTO = new DriverDetailsTO();

        dDetailsTO.setContactNumber(contactNumber);
        dDetailsTO.setUsername(userName);
        dDetailsTO.setEmailAddress(emailAddress);
        dDetailsTO.setFirstName(firstName);
        dDetailsTO.setLastName(lastName);
        dDetailsTO.setHomeAddress(homeAddress);

        DriverLicenceTypeEntity driverLicenceTypeEntity = new DriverLicenceTypeEntity();

        driverLicenceTypeEntity.setCode(driverLicenceCode);
        driverLicenceTypeEntity.setDescription(driverLicenceDescription);

        dDetailsTO.setDriverLicenceType(driverLicenceTypeEntity);

        try {
            driverRemote.insertNewDriver(dDetailsTO);
        } catch (Exception ex) {
        }
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }


    public String getContactNumber() {
        return contactNumber;
    }

    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    public String getDriverLicenceCode() {
        return driverLicenceCode;
    }

    public void setDriverLicenceCode(String driverLicenceCode) {
        this.driverLicenceCode = driverLicenceCode;
    }

    public DriverRemote getDriverRemote() {
        return driverRemote;
    }

    public void setDriverRemote(DriverRemote driverRemote) {
        this.driverRemote = driverRemote;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getHomeAddress() {
        return homeAddress;
    }

    public void setHomeAddress(String homeAddress) {
        this.homeAddress = homeAddress;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getDriverLicenceDescription() {
        return driverLicenceDescription;
    }

    public void setDriverLicenceDescription(String driverLicenceDescription) {
        this.driverLicenceDescription = driverLicenceDescription;
    }

}
